Using the Low-Level Interface

System 7 Pack’s low-level interface gives you total control for sending and receiving more complex AppleEvents. These commands are very similar to the functions documented in the AppleEvent Manager chapter of Inside Macintosh Volume 6 or New Inside Macintosh: Interapplication Communication.

Sending an AppleEvent using the low-level interface involves creating the event, adding parameters to it, sending it, and finally disposing of the event and the reply.

To create an AppleEvent, call CreateAEVT specifying the target address, a 4-character event class, and a 4-character event ID. To add parameters to the AppleEvent, call PutShortParam, PutLongParam, PutTextParam, PutAliasParam, PutObject, PutPicParam,  or PutList, depending on the data type to be used.

The PutObject command can be used to include an object specifier in your AppleEvent, which allows you to tell the receiving application to act on one specific piece of data such as a particular window, a word or paragraph in a particular document, or an object in a drawing. Object specifiers may be nested to represented objects contained in another object (called a container). For example, an object specifier might be something like ‘the first character of the second word of the fifth paragraph in the document named “gone with the wind”’.

Objects are always identified by a 4-letter class ID and either a numeric value or a name and an optional container, which will be 0 (null) for the top-level object. For example, a paragraph may be contained in a document or window, but a window or document has no container other than the application itself, so their container would be 0. An object also has certain properties, also identified by 4-letter words. Typical properties would be the font, font size, style, and color. See Appendix D for a list of common object classes and property IDs.

Receiving an AppleEvent using the low-level commands is much easier, since most of the work is already done for you by the AppleEvent manager. When an AppleEvent is received, the procedure that was installed with HandleAEVT will be called. It can use a combination of low-level and high-level functions to obtain data from the AppleEvent.

When receiving anything more complex than a single text or numeric direct object, you should use the commands GetShortParam, GetLongParam, GetTextParam, GetAliasParam, GetPicParam, or GetList to extract data from the event. Note that there is no way to receive an object specifier, since 4D® doesn’t provide a way to resolve them into references to actual data.